package com.example.majiang.mapper;

import com.example.majiang.model.Notification;
import com.example.majiang.model.Question;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NotificationMapper {
    @Insert("insert into notification(notifier, receiver, outerid, type, gmtCreate, status, notifierName, outerTitle) values(#{notifier}, #{receiver}, #{outerid}, #{type}, #{gmtCreate}, #{status}, #{notifierName}, #{outerTitle})")
    void insert(Notification notification);
    @Select("select count(*) from notification where receiver=#{receiver}")
    Integer CountByReceiver(@Param("receiver") Integer receiver);
    @Select("select * from notification where receiver = #{userId} limit #{offset},#{size}")
    List<Notification> listByUserId(@Param("userId") Integer userId, @Param(value = "offset") Integer offset, @Param(value = "size") Integer size);
    @Select("select count(*) from notification where receiver=#{receiver} and status=#{status}")
    Integer countUnRead(@Param("receiver")Integer receiver,@Param("status")Integer status);
    @Select("select * from notification where id=#{id}")
    Notification selectById(@Param("id")Integer id);
    @Select("update notification set status=#{status} where id=#{id}")
    void updateRead(@Param("status")Integer status,@Param("id")Integer id);

}
